#import "YYText.h"
#import "GKCover.h"
#import "dfhgwhruebvhrheyluggagerecorder.h"
#import "dfhgwhruebvhrheyleatherfreight.h"
#import "dfhgwhruebvhrheybatchspot.h"
#import "dfhgwhruebvhrheycapableintellectual.h"
#import "dfhgwhruebvhrheysecurityinjure.h"
#import "dfhgwhruebvhrheyequatorprove.h"
#import "dfhgwhruebvhrheyconcealwarrantViewController.h"
@interface dfhgwhruebvhrheyconcealwarrantViewController ()
@property (weak, nonatomic) IBOutlet YYLabel *tipsText;
@property (weak, nonatomic) IBOutlet UILabel *userNameText;
@property (weak, nonatomic) IBOutlet dfhgwhruebvhrheysecurityinjure *userNameInput;
@property (weak, nonatomic) IBOutlet UILabel *accountNameText;
@property (weak, nonatomic) IBOutlet dfhgwhruebvhrheysecurityinjure *accountNameInput;
@property (weak, nonatomic) IBOutlet UILabel *accountNoText;
@property (weak, nonatomic) IBOutlet dfhgwhruebvhrheysecurityinjure *accountNoInput;
@property (weak, nonatomic) IBOutlet UILabel *sameAccountText;
@property (weak, nonatomic) IBOutlet dfhgwhruebvhrheysecurityinjure *sameAccountInput;
@property (weak, nonatomic) IBOutlet UIView *cellPhoneView;
@property (weak, nonatomic) IBOutlet UILabel *cellPnoneText;
@property (weak, nonatomic) IBOutlet dfhgwhruebvhrheysecurityinjure *cellPhoneInput;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *cellPhoneViewHeight;
@property (nonatomic, copy) NSString *userName;
@property (nonatomic, copy) NSString *account_id;
@property (nonatomic, copy) NSString *accountName;
@property (nonatomic, copy) NSString *accountNumber;
@property (nonatomic, copy) NSString *accountSameNo;
@property (nonatomic, copy) NSString *cellPhoneNumber;
@property (nonatomic, strong) dispatch_group_t group;
@property (nonatomic, strong) dfhgwhruebvhrheycapableintellectual *popView;
@property (nonatomic, strong) dfhgwhruebvhrheybatchspot *userModel;
@property (nonatomic, strong) NSMutableArray<dhgfywegwygeydwpursuitlaser *> *nameList;
@end
@implementation dfhgwhruebvhrheyconcealwarrantViewController {
	void(^_result)(BOOL ret);
}
- (dfhgwhruebvhrheycapableintellectual *)popView {
	if(!_popView) {
		_popView = [[NSBundle mainBundle] loadNibNamed:@"dfhgwhruebvhrheycapableintellectual" owner:nil options:nil].firstObject;
	}
	return _popView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
	[self loadUI];
	[self loadData];
	switch (self.onLineStyle) {
		case dhgfywegwygeydwsemesterfurious: {
			[dfhgwhruebvhrheyoptionsaving uploadRiskDataByCatchId:@"11" andApplyId:nil withDetailId:nil];
		}
			break;
		case dhgfywegwygeydwexaggeratesemester: {
			[dfhgwhruebvhrheyoptionsaving uploadRiskDataByCatchId:@"13" andApplyId:nil withDetailId:nil];
		}
			break;
		default:
			break;
	}
}
- (void)loadData {
	if (self.group == nil) {	
		self.group = dispatch_group_create();
	}
	dispatch_group_enter(self.group);
	[self loadUserInfo];
	dispatch_group_enter(self.group);
	[self loadAccountNameList];
	[dfhgwhruebvhrheyoptionsaving.keyWindow startLoading];
	__weak typeof(self) weakSelf = self;
	dispatch_group_notify(self.group, dispatch_get_main_queue(), ^{
		__strong typeof(weakSelf) strongSelf = weakSelf;
		[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
		[strongSelf bindData];
	});
}
- (void)loadUserInfo {
	__weak typeof(self) weakSelf = self;
	[[dfhgwhruebvhrheyluggagerecorder shareInstance] dhgfywegwygeydwbarrierawait:dhgfywegwygeydwlambbreast path:userInfoDataApi isEncrypt:YES withParams:nil success:^(NSURLSessionDataTask * _Nonnull task, NSString * _Nonnull json) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		strongSelf.userModel = [dfhgwhruebvhrheybatchspot yy_modelWithJSON:json];
		dispatch_group_leave(strongSelf.group);
	} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		dispatch_group_leave(strongSelf.group);
	}];
}
- (void)loadAccountNameList {
	NSString *apiPath = ewalletNameListApi;
	if (self.onLineStyle == dhgfywegwygeydwsemesterfurious) {
		apiPath = bankNameListApi;
	}
	__weak typeof(self) weakSelf = self;
	[[dfhgwhruebvhrheyluggagerecorder shareInstance] dhgfywegwygeydwbarrierawait:dhgfywegwygeydwlambbreast path:apiPath isEncrypt:YES withParams:nil success:^(NSURLSessionDataTask * _Nonnull task, NSString * _Nonnull json) {
		[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
		__strong typeof(weakSelf) strongSelf = weakSelf;
		dfhgwhruebvhrheyequatorprove *model = [dfhgwhruebvhrheyequatorprove yy_modelWithJSON:json];
		if (model.code == 200) {
			for (dhgfywegwygeydwlaserbeforehand *item in model.data) {
				dhgfywegwygeydwpursuitlaser *itemModel = [[dhgfywegwygeydwpursuitlaser alloc] init];
				if (strongSelf.onLineStyle == dhgfywegwygeydwsemesterfurious) {
					itemModel.item_id = item.bankid;
					itemModel.title = item.bankname;
				}else {
					itemModel.item_id = item.e_id;
					itemModel.title = item.title;
				}
				[strongSelf.nameList addObject:itemModel];
			}
		}else {
			[dfhgwhruebvhrheyoptionsaving.keyWindow show:model.error];
		}
		dispatch_group_leave(strongSelf.group);
	} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		dispatch_group_leave(strongSelf.group);
	}];
}
- (void)bindData {
	NSString *userName = [NSString stringWithFormat:@"%@%@%@", self.userModel.name_one, self.userModel.name_two, self.userModel.name_three];
	[self.userNameInput bindContent:userName];
	self.userName = userName;
}
- (void)loadUI {
	if (self.onLineStyle == dhgfywegwygeydwexaggeratesemester) {
		self.cellPhoneView.hidden = YES;
		self.cellPhoneViewHeight.constant = 0;
		self.accountNameText.text = @"E-Wallet Name";
		self.accountNoText.text = @"E-Wallet Account No.";
		self.sameAccountText.text = @"Same E-wallet Account No.";
		self.navigationItem.title = @" E-Wallet";
		self.accountNoInput.contentType = dhgfywegwygeydwbeforehandversion;
		self.accountNoInput.keyboardType = UIKeyboardTypeNumberPad;
		self.sameAccountInput.contentType = dhgfywegwygeydwbeforehandversion;
		self.sameAccountInput.keyboardType = UIKeyboardTypeNumberPad;
	}else {
		self.cellPhoneView.hidden = NO;
		self.cellPhoneViewHeight.constant = 77;
		self.accountNameText.text = @"Bank Name";
		self.accountNoText.text = @"Bank Account No.";
		self.sameAccountText.text = @"Same Bank Account No.";
		self.navigationItem.title = @"Add Bank Card";
		self.accountNoInput.contentType = dhgfywegwygeydwversionvictim;
		self.accountNoInput.keyboardType = UIKeyboardTypeNumberPad;
		self.sameAccountInput.contentType = dhgfywegwygeydwversionvictim;
		self.sameAccountInput.keyboardType = UIKeyboardTypeNumberPad;
		self.cellPhoneInput.contentType = dhgfywegwygeydwbeforehandversion;
		self.cellPhoneInput.keyboardType = UIKeyboardTypeNumberPad;
	}
	self.nameList = [@[] mutableCopy];
	[self configBackIcon:@"dhgfywegwygeydwcurvereciprocal"];
	self.navigationStyle = dhgfywegwygeydwreciprocaltransport;
	NSMutableAttributedString *tipsAttribute = [[NSMutableAttributedString alloc] initWithString:@"1. This wallet is for recerving transaction.\n2. Please ensure that the account information you entered is accurate and available. the user shall be take whole responsibility for incorrect information filled in by the themselves."];
	NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
	style.lineSpacing = 5;
	[tipsAttribute addAttributes:@{
		NSParagraphStyleAttributeName: style,
		NSFontAttributeName: [UIFont regular:14],
		NSForegroundColorAttributeName: @"#AAAAAA".dhgfywegwygeydwlearneddesignate
	} range:NSMakeRange(0, tipsAttribute.length)];
	self.tipsText.numberOfLines = 0;
	self.tipsText.attributedText = tipsAttribute;
	__weak typeof(self) weakSelf = self;
	[self.userNameInput inputTextChanged:^(UITextField * _Nonnull inputTextField) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		if ([strongSelf.userNameInput.subviews containsObject:inputTextField]) {
			strongSelf.userName = inputTextField.text;
		}
	}];
	[self.accountNameInput inputTextViewClick:^(dfhgwhruebvhrheysecurityinjure * _Nonnull clickView) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		[strongSelf selectAccountName];
	}];
	[self.accountNoInput inputTextChanged:^(UITextField * _Nonnull inputTextField) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		if ([strongSelf.accountNoInput.subviews containsObject:inputTextField]) {
			strongSelf.accountNumber = inputTextField.text;
		}
	}];
	[self.sameAccountInput inputTextChanged:^(UITextField * _Nonnull inputTextField) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		if ([strongSelf.sameAccountInput.subviews containsObject:inputTextField]) {
			strongSelf.accountSameNo = inputTextField.text;
		}
	}];
	[self.cellPhoneInput inputTextChanged:^(UITextField * _Nonnull inputTextField) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		if ([strongSelf.cellPhoneInput.subviews containsObject:inputTextField]) {
			strongSelf.cellPhoneNumber = inputTextField.text;
		}
	}];
}
- (void)addAccountResult:(void(^)(BOOL ret))result {
	_result = result;
}
- (void)bindSuccess {
	if(_result) {
		_result(YES);
	}
	switch (self.onLineStyle) {
		case dhgfywegwygeydwsemesterfurious: {
			[dfhgwhruebvhrheyoptionsaving uploadRiskDataByCatchId:@"12" andApplyId:nil withDetailId:nil];
		}
			break;
		case dhgfywegwygeydwexaggeratesemester: {
			[dfhgwhruebvhrheyoptionsaving uploadRiskDataByCatchId:@"14" andApplyId:nil withDetailId:nil];
		}
			break;
		default:
			break;
	}
	[self.navigationController popViewControllerAnimated:YES];
}
- (void)selectAccountName {
	[self.view endEditing:YES];
	__weak typeof(self) weakSelf = self;
	self.popView.popTitle = self.accountNameText.text;
	[GKCover coverFrom:[dfhgwhruebvhrheyoptionsaving keyWindow] contentView:self.popView style:GKCoverStyleTranslucent showStyle:GKCoverShowStyleCenter showAnimStyle:GKCoverShowAnimStyleCenter hideAnimStyle:GKCoverHideAnimStyleCenter notClick:YES];
	[self.popView bindPopData:self.nameList andSelect:^(dhgfywegwygeydwpursuitlaser * _Nonnull select) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		[GKCover hideCover];
		if (select != nil) {
			[strongSelf.accountNameInput bindContent:select.title];
			strongSelf.accountName = select.title;
			strongSelf.account_id = select.item_id;
		}
	}];
}
- (IBAction)bindAction {
	if (!self.userName.dhgfywegwygeydwagitationscholarship) {
		return [dfhgwhruebvhrheyoptionsaving.keyWindow show:@"Please input your name in the correct format!"];
	}
	if (self.onLineStyle == dhgfywegwygeydwexaggeratesemester) {
		if (!self.accountNumber.dhgfywegwygeydwdesignatecommence) {
			return [dfhgwhruebvhrheyoptionsaving.keyWindow show:@"Please fill in the correct format for the phone number，which must start with 9, 09, 8 or 08"];
		}
		if (![self.accountNumber isEqualToString:self.accountSameNo]) {
			return [dfhgwhruebvhrheyoptionsaving.keyWindow show:@"The accounts filled in twice are different. Please check again"];
		}
	}else {
		if (self.accountNumber.length == 0) {
			return [dfhgwhruebvhrheyoptionsaving.keyWindow show:@"Bank account cannot empty"];
		}
		if (self.accountNumber.length < 10) {
			return [dfhgwhruebvhrheyoptionsaving.keyWindow show:@"Bank account format error"];
		}
		if (![self.accountNumber isEqualToString:self.accountSameNo]) {
			return [dfhgwhruebvhrheyoptionsaving.keyWindow show:@"The accounts filled in twice are different. Please check again"];
		}
		if (!self.cellPhoneNumber.dhgfywegwygeydwdesignatecommence) {
			return [dfhgwhruebvhrheyoptionsaving.keyWindow show:@"Please fill in the correct format for the phone number，which must start with 9, 09, 8 or 08"];
		}
	}
	NSString *apiPath = bindBankApi;
	NSMutableDictionary *params = [@{} mutableCopy];
	if (self.onLineStyle == dhgfywegwygeydwsemesterfurious) {
		if (!self.cellPhoneNumber.dhgfywegwygeydwdesignatecommence) {
			return [dfhgwhruebvhrheyoptionsaving.keyWindow show:@"Please fill in the correct format for the phone number，which must start with 9, 09, 8 or 08"];
		}
		params[@"bid"] = self.account_id;
		params[@"username"] = self.userName;
		params[@"mobile"] = self.cellPhoneNumber;
		params[@"bank_number"] = self.accountNumber;
	}else {
		apiPath = bindEwalletApi;
		params[@"channel_id"] = self.account_id;
		params[@"account_number"] = self.accountNumber;
	}
	[dfhgwhruebvhrheyoptionsaving.keyWindow startLoading];
	__weak typeof(self) weakSelf = self;
	NSString *json = [params yy_modelToJSONString];
	[[dfhgwhruebvhrheyluggagerecorder shareInstance] dhgfywegwygeydwbarrierawait:dhgfywegwygeydwawaitlamb path:apiPath isEncrypt:YES withParams:@{@"data":json} success:^(NSURLSessionDataTask * _Nonnull task, NSString * _Nonnull json) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
		dfhgwhruebvhrheysternideology *model = [dfhgwhruebvhrheysternideology yy_modelWithJSON:json];
		if (model.code == 200) {
			[strongSelf bindSuccess];
		}else {
			[dfhgwhruebvhrheyoptionsaving.keyWindow show:model.error];
		}
	} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
		[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
	}];
}
@end
